home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / isave.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.7 KB  |  119 lines

  1. /* Copyright (C) 1991, 1995, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: isave.h,v 1.2 2000/09/19 19:00:46 lpd Exp $ */
  20. /* Procedures for save/restore */
  21. /* Requires imemory.h */
  22.  
  23. #ifndef isave_INCLUDED
  24. #  define isave_INCLUDED
  25.  
  26. #include "idosave.h"
  27.  
  28. /*
  29.  * According to the PostScript language definition, save objects are simple,
  30.  * not composite.  Consequently, we cannot use their natural representation,
  31.  * namely a t_struct pointing to an alloc_save_t, since we aren't willing to
  32.  * allocate them all in global VM and rely on garbage collection to clean
  33.  * them up.  Instead, we assign each one a unique "save ID", and store this
  34.  * in the alloc_save_t object.  Mapping the number to the object requires
  35.  * at most searching the local save chain for the current gs_dual_memory_t,
  36.  * and this approach means we don't have to do anything to invalidate
  37.  * save objects when we do a restore.
  38.  */
  39. #ifndef alloc_save_t_DEFINED    /* also in inamedef.h */
  40. typedef struct alloc_save_s alloc_save_t;
  41. #  define alloc_save_t_DEFINED
  42. #endif
  43.  
  44. /* Initialize the save machinery. */
  45. extern void alloc_save_init(P1(gs_dual_memory_t *));
  46.  
  47. /* Map a save ID to its save object.  Return 0 if the ID is invalid. */
  48. alloc_save_t *alloc_find_save(P2(const gs_dual_memory_t *, ulong));
  49.  
  50. /*
  51.  * Save the state.  Return 0 if we can't allocate the save object,
  52.  * otherwise return the save ID.  The second argument is a client data
  53.  * pointer, assumed to point to an object.
  54.  */
  55. ulong alloc_save_state(P2(gs_dual_memory_t *, void *));
  56.  
  57. /* Get the client pointer passed to alloc_saved_state. */
  58. void *alloc_save_client_data(P1(const alloc_save_t *));
  59.  
  60. /* Return (the id of) the innermost externally visible save object. */
  61. ulong alloc_save_current_id(P1(const gs_dual_memory_t *));
  62. alloc_save_t *alloc_save_current(P1(const gs_dual_memory_t *));
  63.  
  64. /* Check whether a pointer refers to an object allocated since a given save. */
  65. bool alloc_is_since_save(P2(const void *, const alloc_save_t *));
  66.  
  67. /* Check whether a name was created since a given save. */
  68. bool alloc_name_is_since_save(P2(const ref *, const alloc_save_t *));
  69. bool alloc_name_index_is_since_save(P2(uint, const alloc_save_t *));
  70.  
  71. /*
  72.  * Check whether any names have been created since a given save
  73.  * that might be released by the restore.
  74.  */
  75. bool alloc_any_names_since_save(P1(const alloc_save_t *));
  76.  
  77. /*
  78.  * Do one step of restoring the state.  Return true if the argument
  79.  * was the innermost save, in which case this is the last (or only) step.
  80.  * Assume the caller obtained the argument by calling alloc_find_save;
  81.  * if this is the case, the operation cannot fail.
  82.  */
  83. bool alloc_restore_step_in(P2(gs_dual_memory_t *, alloc_save_t *));
  84. /* Backward compatibility */
  85. #define alloc_restore_state_step(save) alloc_restore_step_in(idmemory, save)
  86.  
  87. /*
  88.  * Forget a save -- like committing a transaction (restore is like
  89.  * aborting a transaction).  Assume the caller obtained the argument
  90.  * by calling alloc_find_save.  Note that forgetting a save does not
  91.  * require checking pointers for recency.
  92.  */
  93. void alloc_forget_save_in(P2(gs_dual_memory_t *, alloc_save_t *));
  94. /* Backward compatibility */
  95. #define alloc_forget_save(save) alloc_forget_save_in(idmemory, save)
  96.  
  97. /* Release all memory -- like doing a restore "past the bottom". */
  98. void alloc_restore_all(P1(gs_dual_memory_t *));
  99.  
  100. /* ------ Internals ------ */
  101.  
  102. /*
  103.  * If we are in a save, we want to save the old contents if l_new is
  104.  * not set; if we are not in a save, we never want to save old contents.
  105.  * We can test this quickly with a single mask that is l_new if we are
  106.  * in a save, and -1 if we are not, since type_attrs of a valid ref
  107.  * cannot be 0; this is the test_mask in a gs_dual_memory_t.  Similarly,
  108.  * we want to set the l_new bit in newly allocated objects iff we are in
  109.  * a save; this is the new_mask in a gs_dual_memory_t.
  110.  */
  111.  
  112. /* Record that we are in a save. */
  113. void alloc_set_in_save(P1(gs_dual_memory_t *));
  114.  
  115. /* Record that we are not in a save. */
  116. void alloc_set_not_in_save(P1(gs_dual_memory_t *));
  117.  
  118. #endif /* isave_INCLUDED */
  119.